package com.aliyun.messagemgt.application.service.Impl;

import com.aliyun.messagemgt.common.annotation.PagingAnnotation;
import com.aliyun.messagemgt.application.service.InterFaceLogService;
import com.aliyun.messagemgt.dto.push.InterfaceLog;
import com.aliyun.messagemgt.dto.query.InterFaceLogQuery;
import com.aliyun.messagemgt.domain.repository.InterfaceLogRepository;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 *@Author Znight
 *@Date 15:32 2019/6/9
 */
@Service
public class InterFaceLogServiceImpl implements InterFaceLogService {


    @Resource
    InterfaceLogRepository interfaceLogRepository;

    @Override
    @PagingAnnotation
    public PageInfo<com.aliyun.messagemgt.dto.InterfaceLog> queryInterfaceLogList(InterFaceLogQuery interFaceLog) {
        PageHelper.startPage(interFaceLog.getPageNum(), interFaceLog.getPageSize());
        List<com.aliyun.messagemgt.dto.InterfaceLog> interfaceLogs = interfaceLogRepository.queryInterfaceLogList(interFaceLog);
        PageInfo pageInfo = new PageInfo(interfaceLogs);
        return pageInfo;
    }
    @Override
    public int countInterfaceLogList(InterFaceLogQuery interFaceLog) {
        return interfaceLogRepository.countInterfaceLogList(interFaceLog);
    }

    @Override
    public void insertSelective(List<InterfaceLog> interfaceLogList) {
        List<com.aliyun.messagemgt.dto.InterfaceLog> interfaceLogs = new ArrayList<>();
        for (InterfaceLog temp:interfaceLogList) {
            com.aliyun.messagemgt.dto.InterfaceLog interfaceLog = new com.aliyun.messagemgt.dto.InterfaceLog();
            BeanUtils.copyProperties(temp, interfaceLog);
            interfaceLogs.add(interfaceLog);
        }
        interfaceLogRepository.insertSelective(interfaceLogs);
    }
}
